package com.hx.manager.controller.goods;


import com.hx.common.result.PageResult;
import com.hx.common.result.Result;
import com.hx.goods.pojo.Brand;
import com.hx.goods.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by zxd on 2020/12/31
 **/
@RestController
@RequestMapping("/brand")
@Api(description = "品牌相关接口文档")
public class BrandController {

    @Reference
    private BrandService brandService;

    @ApiOperation(value = "查询所有品牌",notes = "查询所有品牌",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @GetMapping("/findAll")
    public List<Brand> findAll(){
        return brandService.findAll();
    }


    @ApiOperation(value = "分页查询所有品牌",notes = "分页查询所有品牌",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @GetMapping("/findPage")
    public PageResult<Brand> findPage(int page, int size){
        return  brandService.findPage(page,size);
    }


    @ApiOperation(value = "条件查询品牌",notes = "条件查询品牌",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @PostMapping("/findList")
    public List<Brand> findList( @RequestBody Map searchMap){
        return brandService.findList(searchMap);
    }

    @ApiOperation(value = "条件分页查询品牌",notes = "条件分页查询品牌",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @PostMapping("/findPage")
    public PageResult<Brand>  findPage(@RequestBody Map searchMap,int page,int size ){
        return brandService.findPage(searchMap,page,size);
    }

    @ApiOperation(value = "根据id查询品牌",notes = "根据id查询品牌",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @GetMapping("/findById")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @ApiOperation(value = "添加品牌",notes = "添加品牌",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @PostMapping("/add")
    public Result add(@RequestBody  Brand brand){
        brandService.add(brand);
        return new Result();
    }

    @ApiOperation(value = "修改品牌",notes = "修改品牌",httpMethod = "POST")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @PostMapping("/update")
    public Result update(@RequestBody  Brand brand){
        brandService.update(brand);
        return new Result();
    }


    @ApiOperation(value = "删除所有品牌",notes = "删除所有品牌",httpMethod = "DELETE")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功!"),
            @ApiResponse(code=500,message="服务器开小差了!")
    })
    @GetMapping("/delete")
    public Result delete(Integer id){
        brandService.delete(id);
        return new Result();
    }

}
